﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MusicAcademy
{
    public partial class ListOfTools : Form
    {
        public int SelectedID = -1;

        public string ToolName { get; set; }

        public ListOfTools()
        {
            InitializeComponent();
        }


        private void RefreshGrid()
        {
            this.toolTableAdapter.FillByName(this.musicAcademyDataSet.Tool, Program.academyID, txtToolName.Text);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (GrdTool.SelectedRows.Count > 0)
            {
                SelectedID = Convert.ToInt32(GrdTool.SelectedRows[0].Cells["ID"].Value);
                ToolName = GrdTool.SelectedRows[0].Cells["toolName"].Value.ToString();
                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("لطفا یک ساز را انتخاب نمایید.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            SelectedID = -1;
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void grpTool_Enter(object sender, EventArgs e)
        {

        }

        private void ListOfTools_Load(object sender, EventArgs e)
        {
            RefreshGrid();
            GrdTool.ClearSelection();
        }

        private void GrdTool_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
                return;
            SelectedID = Convert.ToInt32(GrdTool.Rows[e.RowIndex].Cells["ID"].Value);
            ToolName = GrdTool.SelectedRows[0].Cells["toolName"].Value.ToString();
            DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void txtToolName_TextChanged(object sender, EventArgs e)
        {
            RefreshGrid();
        }
    }
}
